package com.open4cn.simulator.parser.datacolor.dc600;

import com.open4cn.simulator.answer.LogInstructionAction;
import com.open4cn.simulator.answer.datacolor.ChangeSpecularGloss600Answer;
import com.open4cn.simulator.answer.datacolor.ChangeSpecularGlossAction;
import com.open4cn.simulator.core.answer.AbstractAnswer;
import com.open4cn.simulator.core.answer.AnswerResponse;
import com.open4cn.simulator.core.ext.DataColorStatus;
import com.open4cn.simulator.core.parser.IInstructionParser;
import com.open4cn.simulator.core.parser.InstructionParserChain;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.List;

/**
 * @author yinxiaopeng
 * @version 1.0.0
 * @company 致景科技
 * @department 飞梭BU/研发
 * @description
 * @Email yinxiaopeng@zj.tech
 * @date 2022-05-03 17:41
 */
public class GI00D0 implements IInstructionParser {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    private static final String COMMAND = "*GI  00D0:";

    private ChangeSpecularGloss600Answer answer = new ChangeSpecularGloss600Answer();

    private DataColorStatus dataColorStatus;

    public GI00D0(DataColorStatus dataColorStatus) {
        this.dataColorStatus = dataColorStatus;
        init();
    }

    private void init() {
        answer.setActions(Arrays.asList(
                new LogInstructionAction(),
                new ChangeSpecularGlossAction()
        ));
    }

    @Override
    public Object parse(Object msg, InstructionParserChain chain) {
        String instruction = (String) msg;
        if (!COMMAND.equals(instruction)) {
            return chain.filter(msg);
        }

        AnswerResponse response = this.answer.answer(dataColorStatus, DataColorStatus.SpecularGlossEnum.SCI, instruction);
        return response.getData();
    }

    @Override
    public List<AbstractAnswer> getAnswers() {
        return Arrays.asList(answer);
    }

}
